﻿using CLVisionModbus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CLCommuModbus.Config
{
    public class ConstantConfigOption
    {
        internal Dictionary<string, ConstantConfig> constantValuesDict = new Dictionary<string, ConstantConfig>();
        internal void SetConstant_handShakeMode2()
        {
            ConstantConfig constantConfiguration = null;

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "Command";
            constantConfiguration.Address = 0;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ManFctNo";
            constantConfiguration.Address = 1;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaDinit1";
            constantConfiguration.Address = 2;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaDinit2";
            constantConfiguration.Address = 3;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaDinit3";
            constantConfiguration.Address = 4;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaDinit4";
            constantConfiguration.Address = 5;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaReal1";
            constantConfiguration.Address = 6;
            constantConfiguration.DataType = DataType.FLOAT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);


            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaReal2";
            constantConfiguration.Address = 8;
            constantConfiguration.DataType = DataType.FLOAT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaReal3";
            constantConfiguration.Address = 10;
            constantConfiguration.DataType = DataType.FLOAT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ParaReal4";
            constantConfiguration.Address = 12;
            constantConfiguration.DataType = DataType.FLOAT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);


            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "Para1";
            constantConfiguration.Address = 14;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "Para2";
            constantConfiguration.Address = 15;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            int bitIndex_In = 0;
            for (int i = 0; i < 8; i++)
            {
                constantConfiguration = new ConstantConfig();
                constantConfiguration.Name = "IHandShake0" + i.ToString();
                constantConfiguration.Address = 16;
                constantConfiguration.DataType = DataType.USHORT;
                constantConfiguration.Direction = Direction.PLCToTS;
                constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
                constantConfiguration.IsBit = true;
                constantConfiguration.BitIndex = bitIndex_In;
                bitIndex_In += 1;
                constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);
            }

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "StartSingle";
            constantConfiguration.Address = 16;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantConfiguration.IsBit = true;
            constantConfiguration.BitIndex = bitIndex_In;
            bitIndex_In += 1;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "Continuous";
            constantConfiguration.Address = 16;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantConfiguration.IsBit = true;
            constantConfiguration.BitIndex = bitIndex_In;
            bitIndex_In += 1;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "CommandOnce";
            constantConfiguration.Address = 16;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "BasSet";
            constantConfiguration.Address = 16;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantConfiguration.IsBit = true;
            constantConfiguration.BitIndex = bitIndex_In;
            bitIndex_In += 1;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "WrkSet";
            constantConfiguration.Address = 16;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.PLCToTS;
            constantConfiguration.ModbusDataType = ModbusDataType.HoldingRegisters;
            constantConfiguration.IsBit = true;
            constantConfiguration.BitIndex = bitIndex_In;
            bitIndex_In += 1;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);



            //output
            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "RunStates";
            constantConfiguration.Address = 500;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.TSToPLC;
            constantConfiguration.ModbusDataType = ModbusDataType.InputRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "TestplanStates";
            constantConfiguration.Address = 501;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.TSToPLC;
            constantConfiguration.ModbusDataType = ModbusDataType.InputRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "ResultStates";
            constantConfiguration.Address = 502;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.TSToPLC;
            constantConfiguration.ModbusDataType = ModbusDataType.InputRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);

            constantConfiguration = new ConstantConfig();
            constantConfiguration.Name = "Mode";
            constantConfiguration.Address = 503;
            constantConfiguration.DataType = DataType.USHORT;
            constantConfiguration.Direction = Direction.TSToPLC;
            constantConfiguration.ModbusDataType = ModbusDataType.InputRegisters;
            constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);


            int bitIndex_Out = 0;
            for (int i = 0; i < 8; i++)
            {
                constantConfiguration = new ConstantConfig();
                constantConfiguration.Name = "OHandShake0" + i.ToString();
                constantConfiguration.Address = 504;
                constantConfiguration.DataType = DataType.USHORT;
                constantConfiguration.Direction = Direction.TSToPLC;
                constantConfiguration.ModbusDataType = ModbusDataType.InputRegisters;
                constantConfiguration.IsBit = true;
                constantConfiguration.BitIndex = bitIndex_Out;
                bitIndex_In += 1;
                constantValuesDict.Add(constantConfiguration.Name, constantConfiguration);
            }
        }
    }
}